package org.dbpt.performance;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class SequenceIntegerGenerator extends IntegerGenerator {
	private int currentValue;

	public SequenceIntegerGenerator() {
		super();
	}

	public SequenceIntegerGenerator(int min, int max) {
		super(min, max);
		currentValue = min;
	}

	public SequenceIntegerGenerator(int max) {
		super(max);
	}
	
	@Override
	public void generate(PreparedStatement preparedStatement, int paramIdx) throws SQLException {
		int value;
		synchronized (this) {
			value = currentValue++;
			if(currentValue > getMax()) {
				currentValue = getMin();
			}
		}
		preparedStatement.setInt(paramIdx, value);
	}
	
}
